<template>
  <el-form ref="form" :model="form" :rules="rules" label-width="100px" :label-position="mobileLayout ? 'top' : 'right'">
    <el-form-item label="价格日期" prop="priceDate">
      <el-date-picker
        v-model="form.priceDate"
        type="date"
        placeholder="选择价格日期"
        style="width: 100%"
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="铝价金额" prop="averagePrice">
      <el-input-number
        v-model="form.averagePrice"
        :precision="0"
        :step="1"
        :min="0"
        style="width: 100%">
      </el-input-number>
    </el-form-item>
    <el-form-item label="数据来源" prop="priceSource">
      <el-select v-model="form.priceSource" placeholder="请选择数据来源" style="width: 100%">
        <el-option label="上海铝价" value="shanghai"></el-option>
        <el-option label="长江铝价" value="changjiang"></el-option>
      </el-select>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'AluminumPriceForm',
  props: {
    formData: {
      type: Object,
      default: () => ({
        id: null,
        priceDate: new Date().toISOString().split('T')[0],
        averagePrice: 0,
        priceSource: 'shanghai'
      })
    },
    isMobile: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: { ...this.formData },
      rules: {
        priceDate: [
          { required: true, message: '请选择价格日期', trigger: 'change' }
        ],
        averagePrice: [
          { required: true, message: '请输入铝价金额', trigger: 'blur' }
        ],
        priceSource: [
          { required: true, message: '请选择数据来源', trigger: 'blur' }
        ]
      }
    };
  },
  computed: {
    mobileLayout() {
      return this.isMobile;
    }
  },
  watch: {
    formData: {
      handler(newVal) {
        this.form = { ...newVal };
      },
      deep: true
    }
  },
  methods: {
    validate() {
      return new Promise(resolve => {
        this.$refs.form.validate(valid => resolve(valid));
      });
    },
    resetFields() {
      this.$refs.form.resetFields();
    },
    getFormData() {
      return { ...this.form };
    }
  }
}
</script> 